<?php
require('validate.php');

$filename = 'dayscores.txt';
$r10_filename = "dayscores10.txt";
$r20_filename = "dayscores20.txt";
$r30_filename = "dayscores30.txt";

// Load a different file based on how many rounds was passed.
if ($_POST['r'] == 30) {
	$filename = $r30_filename;
} else if ($_POST['r'] == 20) {
	$filename = $r20_filename;
} else {
	$filename = $r10_filename;
}

//$theData = "";

// Get a file into an array.  
$lines = file($filename);

$handle = fopen($filename, 'r');

// If the current date is newer than the last time the file was modified, then erase all data.
if (date("Ymd", filemtime($filename)) < date("Ymd")) {
	fclose($handle);

	$resetData = " ,0, ,0, ,0, ,0, ,0, ,0, ,0, ,0, ,0, ,0";

	$handle = fopen($filename, 'w');
	fwrite($handle, $resetData);
	fclose($handle);

	echo "&rawScores=" . $resetData;
} else {
	fclose($handle);

	// Loop through our array and build a string to pass back to Flash.
	foreach ($lines as $line_num => $line) {
		//echo "Line #<b>{$line_num}</b> : " . $line . "<br />\n";
		echo "&rawScores=" . $line;
	}
}

?>